package com.education.ai.repository;

import com.education.ai.entity.KnowledgePoint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 知识点资源库接口
 */
@Repository
public interface KnowledgePointRepository extends JpaRepository<KnowledgePoint, Long> {
    
    /**
     * 根据学科查找知识点
     */
    List<KnowledgePoint> findBySubject(String subject);
    
    /**
     * 根据年级查找知识点
     */
    List<KnowledgePoint> findByGrade(String grade);
    
    /**
     * 根据学科和年级查找知识点
     */
    List<KnowledgePoint> findBySubjectAndGrade(String subject, String grade);
    
    /**
     * 根据名称模糊查询知识点
     */
    List<KnowledgePoint> findByNameContaining(String name);
    
    /**
     * 根据名称和学科模糊查询知识点
     */
    List<KnowledgePoint> findByNameContainingAndSubject(String name, String subject);
    
    /**
     * 根据父节点ID查询子知识点
     */
    List<KnowledgePoint> findByParentId(Long parentId);
    
    /**
     * 获取知识点层次结构
     */
    @Query("SELECT k FROM KnowledgePoint k WHERE k.subject = ?1 ORDER BY k.id")
    List<KnowledgePoint> findKnowledgeHierarchyBySubject(String subject);
    
    /**
     * 查找没有父节点的顶级知识点（按学科）
     */
    List<KnowledgePoint> findBySubjectAndParentIdIsNull(String subject);
} 